<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>vue</title>
    <script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'></script>
</head>

<body>
    <div id='app'>
        <navbar></navbar>
        <!-- 全局无法访问局部组件; 局部组件可以访问全局组件 -->
        <!-- <child-lyj></child-lyj> -->
        <game></game>
 
    </div>
</body>
<script>
    // 定义一个全局组件
    Vue.component("navbar", {
        template: ` <div style="background-color: red;border:5px solid greenyellow">
            <button @click="handleLeft">left</button>
            猫眼电影--{{movie}}
            <button @click="handleRight">right</button>
            <game></game>
            <child></child>
        </div>`,
        // data 必须是函数写法
        data() {
            return {
                movie: "小李飞刀"
            }
        },
        methods: {
            handleLeft() {
                console.log('left');
            },
            handleRight() {
                console.log('right');
            }
        },
        computed: {},
        watch: {},
        // 局部组件(可以定义多个)
        components: {
            "child": {
                template: `<div>child--{{movie}}</div>`,
                data() {
                    return {
                        movie: "越狱"
                    }
                }
            }
        }
    });

    Vue.component("game", {
        template: `<div style="background: red;">今晚吃鸡</div>`
    });

    // 根组件
    let vm = new Vue({
        el: '#app',
        data: {
            movie: "教父"
        },
        methods: {
            handleLeft() {
                console.log('left----');
            },
        }
    });
</script>

</html>